<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>我的收藏</title>
    <link rel="icon" href="assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
</head>

<script src="./js/vue/vue.js"></script>
<script src="./js/vue/vuetify.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script src="./js/plugins/jquery/jquery.cookie.js"></script>

<body>

<!-- 头部栏位 -->
<!--页面顶部，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
<div id="nav-bottom"></div>
<script type="text/javascript">$("#nav-bottom").load("top.html");</script>

<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>

<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
</body>
    <!--header-->
<div class="goods-list" id="goods-list" >
    <div id="account" >
        <div class="py-container">
            <div class="yui3-g collect">
                <!--左侧列表-->
                <div class="yui3-u-1-6 list">

                    <div class="person-info">
                        <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                        <div class="person-account">
                            <span class="name">{{user.username}}</span>
                            <span class="safe"><a href="#" @click="logout">退出登录 </a></span>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="list-items">
                        <dl>
							<dt><i>·</i> 订单中心</dt>
							<dd ><a href="home-index.html"   >我的订单</a></dd>
							<dd><a href="home-order-pay.html" >待付款</a></dd>
							<dd><a href="home-order-send.html"  >待发货</a></dd>
							<dd><a href="home-order-receive.html" >待收货</a></dd>
							<dd><a href="home-order-evaluate.html" >待评价</a></dd>
						</dl>
						<dl>
							<dt><i>·</i> 我的中心</dt>
							<dd><a href="home-person-collect.html" class="list-active">我的收藏</a></dd>
							<dd><a href="home-person-footmark.html">我的足迹</a></dd>
						</dl>
						<dl>
							<dt><i>·</i> 物流消息</dt>
						</dl>
						<dl>
							<dt><i>·</i> 设置</dt>
							<dd><a href="home-setting-info.html">个人信息</a></dd>
							<dd><a href="home-setting-address.html"  >地址管理</a></dd>
							<dd><a href="home-setting-safe.html" >安全管理</a></dd>
						</dl>
                    </div>
                </div>
                <!--右侧主内容-->
                <!--右侧主内容-->
                <div class="yui3-u-5-6 goods">
                    <div class="body">
                        <h4>收藏的商品</h4>

                            <ul class="yui3-g">
                                <li class="yui3-u-1-4"   v-for="(favorite,j) in favoriteList" :key="favorite.id">
                                    <div class="list-wrap">
                                        <a href="#" @click.prevent="delFavorite(j)" class="sui-btn btn-bordered btn-danger">取消收藏</a>
                                        <div class="p-img"><a :href="'/item/'+favorite.spuId+'.html'" target="_blank"><img
                                                :src="favorite.image"/></a></div>
                                        <div class="price"><strong><em>¥</em> <i>{{ly.formatPrice(favorite.price)}}</i></strong></div>
                                        <div class="attr"><em></em>{{favorite.title}}</div>
                                        <div class="cu"><em><span>促</span>满一件可参加超值换购</em></div>
                                        <div class="operate">
                                            <a href="success-cart.html" target="_blank" class="sui-btn btn-bordered btn-danger">加入购物车</a>
                                            <a href="javascript:void(0);" class="sui-btn btn-bordered">对比</a>
                                            <a href="javascript:void(0);" class="sui-btn btn-bordered">降价通知</a>
                                        </div>
                                    </div>
                                </li >

                            </ul>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

	<!-- 底部栏位 -->
	<!--页面底部，由js动态加载-->
	<div class="clearfix footer"></div>
	<script type="text/javascript">$(".footer").load("foot.html");</script>
	<!--页面底部END-->

<script type="text/javascript">
        var vue = new Vue({
            el: "#goods-list",
            data: {
                user: {},
                favoriteList : [],
                ly,
            },
            methods: {
                loadGoods() {
                    ly.http.get("/sku/findAllFavorite").then((response)=>{
                        this.favoriteList=response.data;
                        alert(favoriteList)
                    }).catch((error)=>{
                        console.log(error);
                    });
                },
                delFavorite(j){
                    ly.http.get("/auth/verify").then(resp => {
                        // 已登录
                        this.user = resp.data;
                        ly.http.delete("/sku/delFavorite/"+this.favoriteList[j].skuId).then(() => {
                            alert("取消收藏成功")
                            window.location.href = "http://www.leyou.com/home-person-collect.html"
                        }).catch(() => {
                            alert("取消收藏失败，请重试！");
                        })
                    }).catch(() => {
                        window.location.href = "http://www.leyou.com/login.html";
                    })
                },
                gotoLogin() {
                    window.location = "login.html?returnUrl=" + window.location;
                },
                logout() {
                    // 删除cookie中的token即可
                    Cookies.remove("LY_TOKEN",{
                        path:"/",
                        domain:"leyou.com"
                    });
                    window.location = 'http://www.leyou.com'
                },
            },
            // 钩子函数
            created(){
                // 有token，曾经登录过，查询用户信息
                ly.http.get("/auth/verify")
                    .then(resp => {
                        this.user = resp.data;
                       this.loadGoods();
                    })
                    .catch(() => {
                        // 去登录
                        this.gotoLogin();
                    });
            }
        })
</script>
</html>